package com.xbongbong.pro.service.toolbox.statistic.help;

import com.xbongbong.paas.enums.BelongEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.UserTeamEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;

/**
 * @author gzt
 * @version 1.0
 * @Description -
 * @datetime - 2022/6/1-16:04
 * @since v1.0
 */
public class BIHelp {
    /**
     * 设置 字段是否在data中
     */
    public static boolean setInData(Integer type) {
        FieldTypeEnum fieldType = FieldTypeEnum.getFieldTypeEnum(type);
        if (fieldType != null) {
            if (BelongEnum.SYSTEM.getAlias().equals(fieldType.getBelong()) || BelongEnum.STOCK.getAlias().equals(fieldType.getBelong()) || BelongEnum.WARNING.getAlias().equals(fieldType.getBelong()) || BelongEnum.BATCH.getAlias().equals(fieldType.getBelong())) {
                return false;
            } else {
                return true;
            }
        } else {
            //TODO  异常抛出
        }
        return true;
    }

    /**
     * 判断该表单是否走团队逻辑
     * @param businessType 表单类型
     * @return true 走团队逻辑
     * @author zhouwq
     * @date 2019/6/25 15:59
     */
    public static boolean isTeamLogicByBusinessType(Integer businessType) {
        //判断是否走团队逻辑
        boolean isTeam = false;
        //判断不为pass表
        if (businessType != null && businessType != XbbRefTypeEnum.UNKNOWN.getCode()) {
            // 判断该表单是否走团队逻辑
            isTeam = UserTeamEnum.hasTeam(businessType);
        }
        return isTeam;
    }

    /**
     * 判断是否为时间类型
     * @param fieldType 字段类型
     * @author zhouwq
     * @date 2019/5/22 10:11
     * @return true为时间类型
     */
    public static boolean isDateTimeByFieldType(Integer fieldType) {
        boolean flag = false;
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
        if (fieldTypeEnum != null) {
            switch (fieldTypeEnum) {
                case DATETIME:
                case ADDTIME:
                case UPDATETIME:
                case CLOSETIME:
                case ENDTIME:
                    flag = true;
                    break;
                default:
                    break;
            }
        }
        return flag;
    }
    /**
     * 判断该字段类型是否走团队逻辑
     * @param fieldType 字段类型
     * @param businessType 业务code
     * @return true or false
     */
    public static boolean isTeamLogicByFieldType(Integer fieldType, Integer businessType) {
        boolean isTeamForm = isTeamLogicByBusinessType(businessType);
        boolean isTeamFieldType = FieldTypeEnum.OWNERID.getType().equals(fieldType) || FieldTypeEnum.COUSERID.getType().equals(fieldType);
        return isTeamForm && isTeamFieldType;
    }

}
